<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<h3>JavaScript访问DOM案例</h3>
		<a href="http://www.taobao.com" target="_blank">淘宝</a>
		<a class="jd" href="http://www.jd.com" target="_blank">京东</a>
		<a name="pdd" href="http://www.pinduoduo.com" target="_blank">拼多多</a>
		<a id="cgb" href="http://act.codeboy.com" target="_blank">java培优</a>
		
		<script>
			console.log("使用js获取页面元素内容");		
				
			console.log(document.getElementsByTagName("a")[0].href);
			console.log(document.getElementsByTagName("a")[0].innerText);
		
			console.log(document.getElementsByClassName("jd")[0].href);
			console.log(document.getElementsByClassName("jd")[0].innerText);

			console.log(document.getElementsByName("pdd")[0].href);
			console.log(document.getElementsByName("pdd")[0].innerText);
			
			console.log(document.getElementById("cgb").href="http://www.baidu.com");
			console.log(document.getElementById("cgb").innerText="天猫");
		
			var a = document.getElementsByTagName("a")[0];
			a.innerText = "百度";
			a.href = "http://www.baidu.com";
		</script>
	</body>
</html>
